package com.lanjiu.lib.utils;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class CollectionUtils {

    private CollectionUtils() {
    }

    public static boolean isEmpty(List list) {
        return list == null || list.isEmpty();
    }

    public static boolean isEmpty(Map map) {
        return map == null || map.isEmpty();
    }

    public static boolean isEmpty(Set set) {
        return set == null || set.isEmpty();
    }

    /**
     * 得到去除重复后的集合
     *
     * @param list
     * @return
     */
    public static <T> List<T> distinct(List<T> list) {
        Set set = new HashSet();
        List<T> newList = new ArrayList<>();
        for (Iterator iter = list.iterator(); iter.hasNext(); ) {
            T object = (T) iter.next();
            if (set.add(object))
                newList.add(object);
        }
        return newList;
    }
}
